home *** CD-ROM | disk | FTP | other *** search
- # include <CType.h>
-
- # define EOS '\0'
-
- /*
- * Given an input string containing words separated by whitespace,
- * return a vector (an array of char pointers) containing each
- * separate word. Words enclosed in single or double quotes, or
- * in angle brackets, may contain whitespace; but words must still
- * be separated by whitespace. If not, some words will have their
- * first character truncated. Words may not contain their delimiters.### MPW Shell - Execution of RunMake terminated.
-
- *
- * The parameters are argv[], an empty vector to be
- * filled in; argc, the size of argv[]; and s, the input string.
- *
- * The input string s is mangled by this routine.
- *
- * Returns the number of words seen. This may be larger than argc;
- * if so, only the first argc words are placed in the vector.
- */
- vector (argc, argv, s)
- int argc;
- char *argv[];
- char *s;
- {
- int i = 0; /* Index into argv[] */
- char delim; /* Word delimiter */
-
- while (*s != EOS)
- {
- /* Skip whitespace */
- while (isspace (*s))
- s++;
- if (*s == EOS)
- break;
-
- /* Save a pointer to this word, if there's room */
- if (i < argc)
- argv[i] = s;
- i++;
-
- /* Decide what delimits the word */
- switch (*s)
- {
- case '\'':
- delim = '\''; break;
- case '"':
- delim = '"'; break;
- case '<':
- delim = '>'; break;
- default:
- delim = EOS; break;
- }
-
- /* Find the end of the word */
- s++;
- if (delim == EOS)
- {
- /* Word is delimited by whitespace */
- while (!isspace (*s) && *s != EOS)
- s++;
- }
- else
- {
- /* Word is delimited by a special character */
- while (*s != delim && *s != EOS)
- s++;
- if (*s == delim)
- s++;
- }
-
- /*
- * Place EOS after the end of the word,
- * to terminate it. There's a bug here:
- * if there is no whitespace following the word
- * (for example, <word1>word2 has a regular word
- * following one in angle brackets),
- * the first char of the next word is trashed.
- */
- if (*s == EOS)
- break;
- *s = EOS;
- s++;
- }
-
- /* Done. Return the number of words seen. */
- return (i);
- }